//
//  ShellRechargeHeadView.m
//  ShellWallert
//
//  Created by lvzhao on 2019/9/27.
//  Copyright © 2019年 VV. All rights reserved.
//

#import "ShellRechargeHeadView.h"
#import "ShellRechargeViewModel.h"


@interface  ShellRechargeHeadView()

@property (nonatomic,strong) ShellRechargeViewModel *viewModel;

//地址图片
@property (nonatomic,strong) UIImageView *scanImgView;

//地址
@property (nonatomic,strong) UILabel *addressLab;


@end

@implementation ShellRechargeHeadView

- (instancetype)initViewModel:(LZBaseViewModel *)viewModel
{
    self = [super init];
    if (self) {
        
        self.viewModel = (ShellRechargeViewModel *)viewModel;
        [self setupView];
    }
    return self;
}

#pragma mark - setupView
- (void)setupView{
    
    
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = UIColorHex(0x061D34);
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(28);
        make.width.mas_equalTo(K_SCREENWIDTH - 56);
        make.height.mas_equalTo(366);
    }];
    view.cornerRadius = 6;
   

    ///!!!:二维码
    [view addSubview:self.scanImgView];
    self.scanImgView.cornerRadius = 6;
    [self.scanImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(58);
        make.centerX.mas_equalTo(view.mas_centerX);
        make.width.mas_equalTo(160);
        make.height.mas_equalTo(160);
    }];
    
    UILabel *tipLabel = [UILabel lz_labelWithText:LZLocalizedString(@"扫描获取充值地址") fontSize:k_textFont(14) color:UIColorHex(0xFFFFFF)];
    [tipLabel lz_centerAlignment];
    [view addSubview:tipLabel];
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.scanImgView.mas_bottom).mas_offset(10);
        make.centerX.mas_equalTo(view.mas_centerX);
        make.width.mas_equalTo(K_SCREENWIDTH - 60);
        make.height.mas_equalTo(17);
    }];
    
    
    UIView *addressView = [[UIView alloc] init];
    addressView.cornerRadius = 6;
    addressView.backgroundColor = UIColorHex(0xFFFFFF);
    [view addSubview:addressView];
    [addressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(tipLabel.mas_bottom).mas_offset(15);
        make.centerX.mas_equalTo(view.mas_centerX);
        make.width.mas_equalTo(K_SCREENWIDTH - 100);
        make.height.mas_equalTo(50);
    }];
    
    
    [addressView addSubview:self.addressLab];
    [self.addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(addressView.mas_centerY);
        make.centerX.mas_equalTo(addressView.mas_centerX);
        make.width.mas_equalTo(K_SCREENWIDTH - 70 - 30 - 20);
        make.height.mas_equalTo(50);
    }];
    
    ///!!!:复制
    UIButton *copyBtn = [UIButton lz_buttonTitle:LZLocalizedString(@"复制地址") titleColor:UIColorHex(0xFFFFFF) fontSize:14];
    copyBtn.titleLabel.font = k_textBoldFont(14);
    [view addSubview:copyBtn];
    [copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(addressView.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(K_SCREENWIDTH - 30 - 30);
        make.height.mas_equalTo(20);
    }];
    
    
    ///复制地址
    [[copyBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        
        UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
        pastboard.string = self.addressLab.text;
        showDelayedDismissTitle(LZLocalizedString(@"复制成功"), self);
    }];
    

    [self refreshUI];
    
    @weakify(self);
    [self.viewModel.reloadSubject subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        if([x integerValue] == 3){
            [self refreshUI];
        }
    }];
   
    
  
}



#pragma mark - actions
//点击事件
- (void)sendActions:(UIButton *)sender{
    
    
    NSLog(@"--------");
    switch (sender.tag) {
        case 10:
        {
            
            
        }
            break;
            
        default:
            break;
    }
    
    
}


///刷新UI
- (void)refreshUI {
    
    NSString *address = @"";
    switch (self.viewModel.wallertModel.currencyType) {
        case ShellCurrencyTypeETH_USDT:
        {
            address = self.viewModel.wallertModel.ethAddress;
        }
            break;
            
        default:
            address = self.viewModel.wallertModel.address;

            break;
    }
    
    UIImage *scanImg = [UIImage creatNonInterContentString:address withSize:130];
    self.scanImgView.image = scanImg;
    self.addressLab.text = address;
}
#pragma mark - custool

#pragma mark - get && set
- (UIImageView *)scanImgView{
    if(!_scanImgView){
        _scanImgView = [[UIImageView alloc] init];
        _scanImgView.backgroundColor = UIColor.whiteColor;
        _scanImgView.contentMode = UIViewContentModeCenter;
    }
    return _scanImgView;
    
}

- (UILabel *)addressLab{
    if (!_addressLab) {
        _addressLab = [UILabel lz_createLabWithTextColor:UIColorHex(0x000000) font:k_textBoldFont(12)];
        _addressLab.numberOfLines = 0;
        [_addressLab lz_centerAlignment];
    }
    return _addressLab;
}




@end
